﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.gameState.malaria.component.util;
using imaginecup.information;
using imaginecup.objectManager;
using Imaginecup.gameState.malaria.componentInit;
using Imaginecup.util;
using Imaginecup.gameState.malaria.manager;
using Imaginecup.factory;
using Imaginecup.gameState.malaria.component.factory;
using Imaginecup.gameState.malaria.component.entity.fieldItem;
using imaginecup.util;
using Microsoft.Xna.Framework;
using Imaginecup.util.collision;
using Imaginecup.util.script.malaria;

namespace Imaginecup.gameState.malaria.component.entity.item
{
    public class CmpFlyPaper : BaseItemEntityComponent
    {
        private int m_RequireMoney;
        private double m_FlyPaperTime;

        public CmpFlyPaper(GObjectID a_GID, ObjectManager objMan)
            : base(a_GID, objMan, ComponentTypeID.CID_ITEM_ENTITY)
        {


            m_RequireMoney = 3;
            m_FlyPaperTime = 5;

#if WINDOWS
            m_RequireMoney = ScriptReader.GetScriptReader().GetDataToInt("진득이돈");
            m_FlyPaperTime = ScriptReader.GetScriptReader().GetDataToFloat("진득이유지시간");
#endif
        }

        public override EMessageResult HandleMessage(GMessage a_Msg)
        {
            if (a_Msg.m_Type.MessageTypeID == MessageTypeID.MT_CHECK_INPUT.MessageTypeID)
            {

            }

            return base.HandleMessage(a_Msg);
        }

        public override bool IsUseAble()
        {
            if (!IsSelectAble()) return false;
            IMouseInputHandler input = MouseInputHandler.GetInputHandler();

            Vector2 screen = MalariaState.GetMalariaState().GetMainScreenSize();

            if (input.IsOneClick() && Collision.ContainPoint(Vector2.Zero, screen, input.Position))
            {
                return true;
            }
            return false;
        }

        public override void DisableItem()
        {

            base.DisableItem();
        }

        public override void UseItem(GameTime gameTime)
        {
            IMouseInputHandler input = MouseInputHandler.GetInputHandler();


            ObjectFactory.GetObjectFactory().SetObjectMan(m_ObjectMan);

            CmpFieldFlyPaper flyPaper = (CmpFieldFlyPaper)ObjectFactory.GetObjectFactory().GetObject(MALARIA_COMPONENT_ID.FIELD_FLYPAPER);

            EntityInfo info = new EntityInfo();
#if !XBOX
            info.mPosition = new Vector2(input.MouseState.X, input.MouseState.Y);
#endif
#if XBOX
            info.mPosition = input.Position;
#endif
            info.mSize = new Vector2(50, 50);

            flyPaper.SetDelayTime(m_FlyPaperTime);
            flyPaper.SetEntityInfo(info);

            GameResourceMan.GetResourceMan().AddMoney(-m_RequireMoney);
        }

        public override bool IsStateEnd()
        {
            return false;
        }

        public override bool IsSelectAble()
        {
            if (GameResourceMan.GetResourceMan().GetMoney() > m_RequireMoney)
            {
                return true;
            }

            return false;
        }
    }
}
